<?php

   function date_addmonths($n_months, $timestamp=null)
      {
      if (is_null($timestamp))    $timestamp=time();
      $timestamp_midmonth    = mktime(12, 0, 0, date('n', $timestamp)+$n_months, 15, date('Y', $timestamp));
      return date('t', $timestamp) > date('t', $timestamp_midmonth) ? strtotime(date('t F Y', $timestamp_midmonth)) : 					strtotime(date(date('d', $timestamp).' F Y', $timestamp_midmonth));
      }
        
   function date_diff($date1, $date2)
   {
      // Date format required is yyyy-mm-dd
      
      $date1array = explode("-",$date1);
      $date2array = explode("-",$date2);
      
      // Assume Date 2 is later than Date 1
      
      $months_apart = ($date2array[0] - $date1array[0])*12;    // find the difference in years and multiply by 12
      
      // Month is later in date 1 than in date 2
      // Find the difference of months
      if( $date1array[1] > $date2array[1] )
      {
         $months_apart -= $date1array[1] - $date2array[1];
      }
      else
      {
         $months_apart += $date2array[1] - $date1array[1];
      }
   
      return $months_apart;
   }

?>